package gui;

import javax.swing.JPanel;

import clientPackage.StartClient;
import common.ChatIF;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;

import ocsf.client.AbstractClient;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class IPFrame extends JFrame implements ChatIF{
	private JTextField txtEnterIpHere;
	private IPFrame myself;
	
	
	
	
	public IPFrame() {
		super();
		this.myself=this;
		this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		initialize();
		
	}
	
	public void initialize()
	{
		getContentPane().setLayout(null);
		
		JButton btnConnect = new JButton("Connect");
		btnConnect.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
					String ip = txtEnterIpHere.getText();;
					int port = 5555;
					AcademicFrame aFrame = new AcademicFrame(ip,port);
					  aFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
					  if (aFrame.allow)
					  {			  
						  aFrame.setVisible( true ); // display frame
					  }
					  else
					  {
						  
						  System.exit(0);
					  }
					  myself.setVisible(false);

			}
		});
		btnConnect.setBounds(117, 90, 89, 23);
		getContentPane().add(btnConnect);
		
		txtEnterIpHere = new JTextField();
		txtEnterIpHere.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				txtEnterIpHere.setText("");
			}
		});
		txtEnterIpHere.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		txtEnterIpHere.setText("Please enter IP to connect");
		txtEnterIpHere.setBounds(88, 59, 147, 20);
		getContentPane().add(txtEnterIpHere);
		txtEnterIpHere.setColumns(10);
		
		JLabel lblWellcome = new JLabel("Welcome");
		lblWellcome.setFont(new Font("David", Font.BOLD, 20));
		lblWellcome.setBounds(113, 11, 120, 37);
		getContentPane().add(lblWellcome);
	}

	
	
	
	
	@Override
	public void display(Object message) {
		// TODO Auto-generated method stub
		
	}
}
